package cn.gy.gift.util;

import cn.gy.gift.enums.SystemErrorCode;

//Ajax请求响应对象的类
public class AjaxResult {
    private boolean success = true;
    private String message = "操作成功!";

    //返回到前台对象
    private Object resultObj;
    private Integer code=200;

    public boolean getSuccess() {
        return success;
    }

    public AjaxResult setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public AjaxResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getResultObj() {
        return resultObj;
    }

    public AjaxResult setResultObj(Object data) {
        this.resultObj = data;
        return this;
    }

    //AjaxResult.me()成功
    //AjaxResult.me().setMessage()成功
    //AjaxResult.me().setSuccess(false),setMessage("失败");
    public  static AjaxResult me(){
        return new AjaxResult();
    }



    public static AjaxResult success(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = "操作成功";
        ajaxResult.success = true;
        return ajaxResult;
    }
    public static AjaxResult success(Object obj){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = "操作成功";
        ajaxResult.success = true;
        ajaxResult.resultObj = obj;
        return ajaxResult;
    }

    public static AjaxResult error(){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = "操作失败";
        ajaxResult.success = false;
        return ajaxResult;
    }
    public static AjaxResult error(String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = msg;
        ajaxResult.success = false;
        return ajaxResult;
    }

    public static AjaxResult error(SystemErrorCode systemErrorCode){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.message = systemErrorCode.getMsg();
        ajaxResult.code= systemErrorCode.getCode();
        ajaxResult.success = false;
        return ajaxResult;
    }
}
